package grape.crm.rest.customer.mvc;

import com.baomidou.mybatisplus.core.metadata.IPage;
import grape.common.exception.runtime.RBaseException;
import grape.common.rest.mvc.BaseController;
import grape.crm.rest.customer.form.CustomerCreateForm;
import grape.crm.rest.customer.form.CustomerListPageForm;
import grape.crm.rest.customer.form.CustomerUpdateForm;
import grape.crm.rest.customer.mapper.CustomerWebMapper;
import grape.crm.rest.customer.vo.CustomerVo;
import grape.crm.rest.customerassociatedcontactperson.mapper.CustomerAssociatedContactPersonWebMapper;
import grape.crm.rest.customerbelong.mapper.CustomerBelongWebMapper;
import grape.crm.rest.customercontact.mapper.CustomerContactWebMapper;
import grape.crm.rest.customercredential.mapper.CustomerCredentialWebMapper;
import grape.crm.service.customer.api.ICustomerService;
import grape.crm.service.customer.param.AddCustomerParam;
import grape.crm.service.customer.po.Customer;
import grape.crm.service.customerbelong.api.ICustomerBelongService;
import grape.crm.service.customerbelong.po.CustomerBelong;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;

/**
 * <p>
 * 客户内部调用接口
 * </p>
 *
 * @author yangwei
 * @since 2020-10-2
 */
@RestController
@RequestMapping("/crm/customer")
@ApiIgnore
public class CustomerInnerController extends BaseController<CustomerVo, Customer> {

    @Autowired
    private ICustomerService currentService;

    /**
     *
     * @param addCustomerParam
     * @return
     */
     @PostMapping(value = "/inner")
     @ResponseStatus(HttpStatus.CREATED)
     public Customer create(@RequestBody AddCustomerParam addCustomerParam) {
         // code 唯一检查
         if (currentService.existCode(addCustomerParam.getCode())) {
             throw new RBaseException("编码已存在");
         }
         Customer customer = currentService.addCustomer(addCustomerParam);

         return customer;
     }

}
